package action.admin;

import bdd.admin.BddCompteSpecialSelectRequest;
import service.securite.DroitsAcces;
import service.securite.Erreur;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import bean.compteSpecial.CompteSpecial;
import bean.dossier.Dossier;

/**
 * Servlet implementation class AdminGestionCompteAdmin
 */
public class AdminGestionCompteAdminAction extends Action {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminGestionCompteAdminAction() {
        super();
    }

    public static boolean aLesDroits(HttpServletRequest request) {
    	return DroitsAcces.isSuperAdmin(request);
    }
	
	protected void initSession(HttpServletRequest request )
	{
		HttpSession session = request.getSession();
	}	
	
	public ActionForward execute(final ActionMapping pMapping,
			ActionForm pForm, final HttpServletRequest request,
			final HttpServletResponse pReponse) {
		ActionErrors errors = new ActionErrors();
		this.initSession(request);
		
		if (!aLesDroits(request)) {
			errors.add("errors",new ActionMessage("errors.admin"));
			saveErrors(request,errors); 
			return (new ActionForward(pMapping.getInput()));
		}
		
		String min = "0";
		if ( request.getParameter("min") != null )
			min = request.getParameter("min");
		
		ArrayList<CompteSpecial> listComptes = null;
		try {
			listComptes = BddCompteSpecialSelectRequest.getComptesSpeciaux();
		} catch (Exception e) {
			e.printStackTrace();
		}
		request.setAttribute("comptes", listComptes);
		request.setAttribute("min", min);
		
		return pMapping.findForward("success");
	}

}
